#include <sys/types.h>       
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
/*
 struct sockaddr_in {
 __kernel_sa_family_t  sin_family;      Address family 
  __be16                sin_port;       Port number
 struct in_addr        sin_addr;       Internet addres
*/
/*
struct in_addr {
        __be32  s_addr;
};
*/


int main(){
	
	int s_fd;
	struct sockaddr_in s_addr;
	struct sockaddr_in c_addr;
//	int socket(int domain, int type, int protocol);
	if((s_fd = socket(AF_INET,SOCK_STREAM,0)) == -1){
	
		perror("socket error");
		exit(-1);
	}
//	int bind(int sockfd, const struct sockaddr *addr,socklen_t addrlen);	
	memset(&s_addr,0,sizeof(s_addr));
	s_addr.sin_family = AF_INET;
	s_addr.sin_port = htons(8181);
	inet_aton("127.0.0.1",&(s_addr.sin_addr));

	if(bind(s_fd,(struct sockaddr *)&s_addr,sizeof(s_addr)) == -1){
		perror("bind error");
		exit(-1);
	}

//	int listen(int sockfd, int backlog);
	listen(s_fd,10);

//	while(1){	
//	int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
	int c_size = sizeof(struct sockaddr);
		if((accept(s_fd,(struct sockaddr*)&c_addr,&c_size)) == -1){
			perror("accept error");
		}
		
//	}
	printf("connect succese");	
		while(1);
		return 0;
}
